package com.yellow.orderservice.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yellow.orderservice.entity.Order;
import com.yellow.orderservice.entity.Receiver;
import com.yellow.orderservice.mapper.ReceiverMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: hy
 * @create: 2024-04-16
 */
@Service
public class ReceiverServiceImpl extends ServiceImpl<ReceiverMapper, Receiver> implements ReceiverService {
    @Resource
    private ReceiverMapper receiverMapper;
    @Override
    public void insertReceiver(Receiver receiver) {
        receiverMapper.insert(receiver);
    }

    @Override
    public Long findIdByName(String name) {
        LambdaQueryWrapper<Receiver> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Receiver::getName, name);
        wrapper.select(Receiver::getReceiverId);
        Receiver receiver = receiverMapper.selectOne(wrapper);
        return receiver.getReceiverId();
    }

    @Override
    public List<Receiver> findReceiverByName(String name) {
        LambdaQueryWrapper<Receiver> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Receiver::getName, name);
        return receiverMapper.selectList(wrapper);
    }

    @Override
    public List<Order> getOrdersByReceiverName(String name) {
        return receiverMapper.getOrdersByReceiverName(name);
    }

    @Override
    public Long contReceivers() {
        return receiverMapper.selectCount(null);
    }
}
